import { post, put } from '@/utils/http/Axios'

enum Api {
    getTodoIndex = '/taishan-runtime/api/v2/message_center/index/counter',
    getTodoList = '/taishan-runtime/api/v2/message_center/todo_list/search',
    getMyCreateList = '/taishan-runtime/api/v2/message_center/mycreate_list/search',
    getDoneList = '/taishan-runtime/api/v2/message_center/done_list/search',
    getCcList = '/taishan-runtime/api/v1/message_center/cc_list',
    setBatchProcessApproval = '/taishan-runtime/api/v1/process/process_instance/task/batch_approve_action'
}

// 查询流程中心
export function getTodoIndex(params: ProcessApplicationIdParams) {
    return post(Api.getTodoIndex, params).then(resp => resp.data)
}
// 查询待办
export function getTodoList(data: PageListQuery<ProcessFilter, ProcessSort>) {
    return post(Api.getTodoList, data).then(resp => resp.data)
}
// 查询我申请的
export function getMyCreateList(data: PageListQuery<ProcessFilter, ProcessSort>) {
    return post(Api.getMyCreateList, data).then(resp => resp.data)
}
// 查询已办
export function getDoneList(data: PageListQuery<ProcessFilter, ProcessSort>) {
    return post(Api.getDoneList, data).then(resp => resp.data)
}
//  获取抄送我的列表
export function getCcList(data: PageListQuery<ProcessFilter, ProcessSort>) {
    return post(Api.getCcList, data).then(resp => resp.data)
}
// 批量审批流程
export function setBatchProcessApproval(data: setBatchProcessApprovalParams<ProcessApproveTaskListItem>) {
    return put(Api.setBatchProcessApproval, data).then(resp => resp.data)
}
//  审批流程
export function setProcessApproval(data) {
    return put('/taishan-runtime/api/v7/process/process_instance/task/approve_action', data)
}
// 我发起的--流程撤销
export function processCancel(data) {
    return put('/taishan-runtime/api/v1/process/process_instance/revoke', data)
}
// 流程回退节点列表
export function getRollbackNodeList(data) {
    return post(`/taishan-runtime/api/v3/process/process_instance/process_rollback_node_list`, data)
}
// 审批待办的退回接口
export function processInstanceRollback(data) {
    return put('/taishan-runtime/api/v5/process/process_instance/rollback', data)
}
// 流程催办
export function setProcessUrge(data) {
    const { processInstanceId, approveNodeKey } = data
    return put(`/taishan-runtime/api/v3/process/process_instance/${processInstanceId}/node/${approveNodeKey}/urge`)
}

/*
 *  应用端查看流程详情
 */
export function fetchProcessDetail(
    processInstanceId: string | number,
    taskId: string | number,
    data: any
): Promise<ProcessDetail> {
    return post(`/taishan-runtime/api/v4/process/page_data/${processInstanceId}/task/${taskId}`, data).then(
        resp => resp.data
    )
}
